package cn.janus.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Result implements Serializable {
    private Integer code;
    private String msg;
    private Object data;

    public Result(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
    }

    /**
     * 构造方法:针对于有具体数据返回的控制器方法,比如:微博首页列表、微博详情页.
     */
    public Result(StatusCode statusCode, Object data) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = data;
    }

    public static Result ok(Object data) {
        return new Result(StatusCode.OPERATION_SUCCESS, data);
    }

    public static Result ok() {
        return ok(null);
    }

    public static Result fail(Object data) {
        return new Result(StatusCode.OPERATION_FAIL, data);
    }
}





















